<?php
session_start();
date_default_timezone_get('Asia/Shanghai');
include('function/sqlhandle.php');
include('function/function.php');

$a = empty($_GET['a'])?'index':$_GET['a'];
$b = empty($_GET['b'])?'index':$_GET['b'];
$c = empty($_GET['c'])?'index':$_GET['c'];

define('__A__', $a);
define('__B__', $b);
define('__C__', $c);

$web = array_reverse(selectAll('nav'));
$abc = selectone('nav',"a='$a' and b='$b' and c='$c'");
//print_r($cate);
//print_r($web);

if($a == 'admin')
{
	if($c=='validate')
	{
		include('app/admin/login/php/validate.php');
		die;
	}
	else if(empty($_SESSION['admin']))
	{
		include('app/admin/login/php/index.php');
		die;
	}else if($b=='login'&&$c=='index')
	{
		echo '已登录';
		header('Refresh:1;index.php?a=admin&b=welcome&c=index');
		die;
	}
}

/*权限*/
if(!empty($_SESSION['admin']))
	{
		$roler = $_SESSION['admin']['role_id'];
		
		$auther = selectOne('permission','Id='.$roler,'permission_id')['permission_id'];
		
		$auth = json_decode($auther);
		
		$auths = selectAll('menu');
		
		$power = selectOne('menu',"a='".$a."' and b='".$b."' and c='".$c."'",'*');

		if(!empty($power))
		{
			if(!in_array($power['Id'],$auth))
			{
				echo "<script>alert('无此权限')</script>";
				header('Refresh:0.1;index.php?a=admin&b=welcome&c=index');
				die;
			}
		}	
	}



//print_r($cate);
include("app/{$a}/{$b}/php/{$c}.php");
?>
